function p=mm2dpfit(x,y,z,nx,ny)
%MM2DPFIT Two-Dimensional Polynomial Curve Fitting. (MM)
% MM2DPFIT(X,Y,Z,Nx,Ny) fits the data in X,Y,Z to 2D polynomials
% in X and Y having orders Nx and Ny respectively.
% X, Y, and Z must all be the same size where Z(i)=f(X(i),Y(i)).
% X and Y can be the plaid output of MESHGRID.
% Use MM2DPVAL to evaluate the resulting polynomial vector.
% Use MM2DPSTR to display the polynomial.
%
% The polynomial fit contains terms up to X^Nx and Y^Ny and all
% possible crossproduct terms X^iY^j where i<=Nx, j<=Ny and
% i+j<=max(Nx,Ny). This corresponds to terms in the Taylor series
% expansion of a function of two variables.
% Example: Nx=2, Ny=2, gives the quadratic form:
% p(1) + p(2)X + p(3)X^2 + p(4)Y + p(5)XY + p(6)Y^2
%
% Warning: Fitting to high order 2D polynomials is numerically
% sensitive. Use this function with caution.
%
% See also MM2DPVAL, MM2DPSTR.

% D.C. Hanselman, University of Maine, Orono, ME  04469
% 12/6/96, v5: 1/14/97 5/30/97
% Mastering MATLAB 5, Prentice Hall, ISBN 0-13-858366-8

